package com.scaffold.card.service;

import java.sql.Timestamp;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import wangjg.commons.page.Page;

import com.scaffold.card.dao.CategoryDAO;
import com.scaffold.card.entity.Category;

@Service
@Transactional
public class CategoryService {

	@Autowired
	private CategoryDAO categoryDAO;

	public Category getCategory(Long id ) {
		return this.categoryDAO.findById(id);
	}

	public void save(Category category){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		if(category.getId()==null){
			category.setCreated(now);
			category.setModified(now);
			this.categoryDAO.save(category);
		}else{
			category.setModified(now);
			this.categoryDAO.update(category);
		}
	}

	public void update(Category category){
		Timestamp now = new Timestamp(System.currentTimeMillis());
		category.setModified(now);
		this.categoryDAO.update(category);
	}

	public void delete(Category category){
		this.categoryDAO.delete(category);
	}

	public List<Category> pageQuery(Page page, String keyword, String enabled) {
		return this.categoryDAO.pageQuery(page, keyword, enabled);
	}

	public List<Category> queryValidList(Page page) {
		return this.categoryDAO.queryValidList(page);
	}
	
	public List<Category> getCategoryEnum() {
		return this.categoryDAO.findAll();
	}

}
